﻿/********************************************************************************
** Author           ： nabber
** Creation Date    ： 2013-09-29
** Modifier         ： nabber
** Modicifation Date： 2013--9-29
** Description      ： Web UI Helper Class Library
*********************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeSet.BaseLibrary
{
    /// <summary>
    /// Web UI Helper Class Library
    /// </summary>
    public class WebUIHelper
    {
        /// <summary>
        /// Decrypt the param of QueryString from WebResource.axd
        /// </summary>
        /// <param name="param">the param of QueryString from WebResource.axd</param>
        /// <returns>
        /// Decrypted param
        /// </returns>
        public static string DecryptWebResourceAxdParam(string param)
        {
            Type type = typeof(System.Web.UI.Page);

            //Create Instance Page
            object oPage = Activator.CreateInstance(type);

            //Get DecryptString Methods by Reflection
            System.Reflection.MethodInfo miDecryptString = type.GetMethod("DecryptString",
                                         System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);

            string strClassPurpose = "System.Web.Security.Cryptography.Purpose";
            string strFieldPurpose = "AssemblyResourceLoader_WebResourceUrl";

            var ppWebResourceUrl = System.Reflection.Assembly.GetAssembly(type).GetType(strClassPurpose).GetField(strFieldPurpose).GetValue(null);

            //Get Result
            var result = miDecryptString.Invoke(oPage, new object[] { param, ppWebResourceUrl });

            return result.ToString();
        }
    }
}
